package com.alifi.crm.dal.lottery;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.alifi.crm.dal.IbatisCRUDDAO;
import com.alifi.crm.dal.object.WinRecordDO;

@Repository("winRecordDAO")
public class WinRecordDAOImpl extends IbatisCRUDDAO<WinRecordDO> implements WinRecordDAO {
    
    @Override
    protected String getNamespace() {
        return "act_win_record";
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<WinRecordDO> getWinRecords(String type, final int maxCount) {
    	Map<String,Object> map = new HashMap<String,Object>();
        map.put("type", type);
        map.put("maxCount", maxCount);
        return  this.getSqlMapClientTemplate().queryForList(this.genStmt("getWinRecords"), map);
    }
    
    @SuppressWarnings("unchecked")
    @Override
    public int getWinCountByPiztype(String pizType, String type, String date) {
    	Map<String,String> map = new HashMap<String,String>();
    	map.put("prize_type",pizType);
        map.put("type", type);
        map.put("startGmtCreated", date + " 00:00:00");
        map.put("endGmtCreated", date + " 23:59:59");
        List<WinRecordDO> list = this.getSqlMapClientTemplate().queryForList(this.genStmt("getWinCountByPiztype"), map);
        return list == null ? 0 : list.size();
    }
    
    @SuppressWarnings("unchecked")
    @Override
    public List<WinRecordDO> selectByEmployeeByDate(String employeeNum, String type, String gmtCreated) {
    	Map<String,String> map = new HashMap<String,String>();
    	map.put("employeeNum",employeeNum);
        map.put("type", type);
        map.put("startGmtCreated", gmtCreated + " 00:00:00");
        map.put("endGmtCreated", gmtCreated + " 23:59:59");
        return  this.getSqlMapClientTemplate().queryForList(this.genStmt("selectByEmployeeByDate"), map);
    }
    
    @Override
    public void insertWinRecord(WinRecordDO winRecord) {
        this.getSqlMapClientTemplate().insert(this.genStmt("insertWinRecord"), winRecord);
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<WinRecordDO> selectByEmployeeNum(String employeeNum, String type) {
        Map<String,String> map = new HashMap<String,String>();
        map.put("employeeNum", employeeNum);
        map.put("type", type);
        return  this.getSqlMapClientTemplate().queryForList(this.genStmt("selectByEmployeeNum"),map);
    }
    
}
